package com.imooc.follow.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.commons.model.domain.ResultInfo;
import com.imooc.commons.utils.ResultInfoUtil;
import com.imooc.follow.service.SignService;

/**
 * \* @author: bear
 * \* Date: 2021-08-13-10:49
 * \* describe:
 */
@RestController
@RequestMapping("sign")
public class SignController {

	@Resource
	private SignService signService;
	@Resource
	private HttpServletRequest request;

	/**
	 * 签到，可以补签
	 * @param access_token
	 * @param date 某个日期 yyyy-MM-dd 默认当天
	 * @return
	 */
	@PostMapping
	public ResultInfo<Integer> sign(String access_token,
			@RequestParam(required = false) String date) {

		int count = signService.doSign(access_token, date);
		return ResultInfoUtil.buildSuccess(request.getServletPath(), count);
	}

	/**
	 * 获取签到次数 默认当月
	 *
	 * @param access_token
	 * @param date         某个日期 yyyy-MM-dd
	 * @return
	 */
	@GetMapping("count")
	public ResultInfo<Long> getSignCount(String access_token, String date) {
		Long count = signService.getSignCount(access_token, date);
		return ResultInfoUtil.buildSuccess(request.getServletPath(), count);
	}

	/**
	 * 获取用户签到情况 默认当月
	 *
	 * @param access_token
	 * @param date         某个日期 yyyy-MM-dd
	 * @return
	 */
	@GetMapping
	public ResultInfo<Map<String, Boolean>> getSignInfo(String access_token, String date) {
		Map<String, Boolean> map = signService.getSignInfo(access_token, date);
		return ResultInfoUtil.buildSuccess(request.getServletPath(), map);
	}
}
